package com.droowa.model.service;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.droowa.domain.DeliveryOption;
import com.droowa.domain.MileageOption;
import com.droowa.model.dao.DeliveryOptionDAO;

@Service
public class DeliveryOptionServiceImpl implements DeliveryOptionService{

	@Autowired
	private DeliveryOptionDAO dao;
	
	@Override
	public int joinDeliveryOption(DeliveryOption deliveryOption)
			throws SQLException {
		DeliveryOption dd = getDeliveryOption();
		if(dd!=null){
			int update = modifyDeliveryOption(deliveryOption);
			if(update==1){
				return -1;
			}else{
				return 0;
			}
		}
		return dao.insertDeliveryOption(deliveryOption);
	}

	@Override
	public int removeDeliveryOption() throws SQLException {
		return dao.deleteDeliveryOption();
	}

	@Override
	public int modifyDeliveryOption(DeliveryOption deliveryOption)
			throws SQLException {
		return dao.updateDeliveryOption(deliveryOption);
	}

	@Override
	public DeliveryOption getDeliveryOption() throws SQLException {
		return dao.selectDeliveryOption();
	}
	
}
